//
//  HNHappWishBigTargetCell.m
//  XDEducation
//
//  Created by 星道 on 17/5/25.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "HNHappWishBigTargetCell.h"

@implementation HNHappWishBigTargetCell
{
    IBOutlet UILabel *_RedFlower;
    IBOutlet UILabel *_exchange_name;
    IBOutlet UILabel *_exchange_desc;
    
    IBOutlet UILabel *_exchange_nickname;
    IBOutlet UILabel *_supervisorName;
    IBOutlet UIButton *_StatusButton;
    IBOutlet UIButton *_VideoButton;
    IBOutlet NSLayoutConstraint *_ViedeoConstraint;
    
    IBOutlet UIButton *_UpdateButton;
}


- (void)setModel:(HNHappyWishBigTarget *)Model
{
    _Model = Model;
    _RedFlower.text = [[Model.flowers stringValue] stringByAppendingString:@"朵"];
    _exchange_name.text = Model.exchange_name;
    _exchange_desc.text = Model.exchange_desc;
    _exchange_nickname.text = Model.exchange_nickname;
    _supervisorName.text = Model.supervisorName;
    [self JudgeButtonStatuWithModel:Model];
}



/** 判断按钮状态 */
- (void)JudgeButtonStatuWithModel:(HNHappyWishBigTarget *)Model;
{
    NSInteger uid = [[AccountTool shareAccountTool].currentAccount.uid integerValue];
    NSInteger exchange_uid = [Model.exchange_uid integerValue];
    NSInteger executeConfirm = [Model.executeConfirm integerValue];
    NSInteger supervisorUid = [Model.supervisorUid integerValue];
    NSInteger supervisorConfirm = [Model.supervisorConfirm integerValue];
    NSInteger status = [Model.status integerValue];
    
    /** 旧版星道iOS逻辑 */
    //如果执行人帐号与登录帐号一至
    if (uid == exchange_uid)
    {
        //如果执行没有确认
//        if (executeConfirm == 0)
//        {
//            [_StatusButton setTitle:@"确认" forState:(UIControlStateNormal)];
//        }
//        //如果是执行人但不是监督人
//        else if (supervisorUid == 0 && executeConfirm == 1)
//        {
//            [_StatusButton setTitle:@"对方确认" forState:(UIControlStateNormal)];
//        }
//        //如果是执行人也是监督人
//        else if (supervisorUid == 1 && executeConfirm == 1)
//        {
//            [_StatusButton setTitle:@"兑现" forState:(UIControlStateNormal)];
//        }
//        else
//        {
//        }
//    }
//    else
//    {
//        //如果不是监督人
//        if (supervisorUid == 0)
//        {
//            [_StatusButton setTitle:@"确认" forState:(UIControlStateNormal)];
//        }
//        //如果是监督人但不是执行人
//        else if (supervisorUid == 1 && executeConfirm == 0)
//        {
//            [_StatusButton setTitle:@"对方确认" forState:(UIControlStateNormal)];
//        }
//        //如果是监督人也是执行人
//        else if (supervisorUid == 1 && executeConfirm == 1)
//        {
//            [_StatusButton setTitle:@"兑现" forState:(UIControlStateNormal)];
//        }
//        else
//        {
//        }
//    }
//    
    
    
    /** JAVA逻辑 */
    //如果执行人或者监督人有一方没有确认
    if (executeConfirm == 0 || supervisorConfirm == 0)
    {
        [_StatusButton setTitle:@"确认" forState:(UIControlStateNormal)];
        [_UpdateButton setTitle:@"修改" forState:(UIControlStateNormal)];
        
        //如果是执行人监督人都没有确认
        if (executeConfirm == 0 &&  supervisorConfirm== 0)
        {
            [_StatusButton setTitle:@"确定" forState:(UIControlStateNormal)];
        }
        //如果执行人确认了但监督人没有确认
        else if (executeConfirm == 1 &&  supervisorConfirm== 0)
        {
            //如果当前角色为执行人
            if (uid == exchange_uid)
            {
                [_StatusButton setTitle:@"对方确认" forState:(UIControlStateNormal)];
            }
            //如果当前角色为监督人
            else if (uid == supervisorUid)
            {
                [_StatusButton setTitle:@"确定" forState:(UIControlStateNormal)];
            }
        }
        //如果是执行人没有确认但监督人确认了
        else if (executeConfirm == 0 &&  supervisorConfirm== 1)
        {
            //如果当前角色为执行人
            if (uid == exchange_uid)
            {
                [_StatusButton setTitle:@"确定" forState:(UIControlStateNormal)];
            }
            //如果当前角色为监督人
            else if (uid == supervisorUid)
            {
                [_StatusButton setTitle:@"对方确认" forState:(UIControlStateNormal)];
            }
        }
        
    }
    //执行人与监督人一起确认了
    else
    {
        //已完成
        if (status == 1)
        {
            [_StatusButton setTitle:@"已完成" forState:(UIControlStateNormal)];
            _UpdateButton.hidden = YES;
        }
        //未完成
        else
        {
            [_StatusButton setTitle:@"兑现" forState:(UIControlStateNormal)];
            //如果登录人是执行人
            if (uid == exchange_uid)
            {
                [_StatusButton setTitle:@"兑现" forState:(UIControlStateNormal)];
                _UpdateButton.hidden = NO;
            }
            //如果登录人是监督人
            else if (uid == supervisorUid)
            {
                [_StatusButton setTitle:@"已完成" forState:(UIControlStateNormal)];
                _UpdateButton.hidden = NO;
            }
        }
    }
}
}
@end
